package io.renren.sf.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.renren.sf.entity.ActivecodeEntity;
import io.renren.sf.vo.BookToUnitVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import io.renren.sf.entity.CbTypefaceEntity;
import io.renren.sf.service.CbTypefaceService;
import io.renren.common.utils.R;



/**
 * 
 *
 * @author cyl_txw
 * @email cyl_txw@gmail.com
 * @date 2021-03-31 13:04:11
 */
@RestController
@RequestMapping("sf/cbtypeface")
public class CbTypefaceController {
    @Autowired
    private CbTypefaceService cbTypefaceService;


    @GetMapping("/getWordList")
    public R getWordList(@RequestParam Map<String, Object> params){
        String name = (String) params.get("name");
        QueryWrapper<CbTypefaceEntity> queryWrapper = new QueryWrapper<>();
        System.out.println(name);
        if(!StringUtils.isEmpty(name)){
            queryWrapper.like("name", name);
        }
        long page = Long.parseLong((String) params.get("page"));
        long limit = Long.parseLong((String) params.get("limit"));
        Page<CbTypefaceEntity> wordPage = new Page<>(page, limit);
        cbTypefaceService.page(wordPage, queryWrapper);
        return R.ok().put("wordPage", wordPage);
    }
    @GetMapping("/getWordAllList")
    public R getWordAllList(){
        return R.ok().put("zList", cbTypefaceService.list());
    }
    /**
     * 信息
     */
    @GetMapping("/info/{id}")
    //@RequiresPermissions("sf:cbtypeface:info")
    public R info(@PathVariable("id") Long id){
		CbTypefaceEntity cbTypeface = cbTypefaceService.getById(id);

        return R.ok().put("cbTypeface", cbTypeface);
    }

    /**
     * 保存
     */
    @PostMapping("/save")
    //@RequiresPermissions("sf:cbtypeface:save")
    public R save(@RequestBody CbTypefaceEntity cbTypeface){
		cbTypefaceService.save(cbTypeface);

        return R.ok();
    }

    /**
     * 修改
     */
    @PostMapping("/update")
    //@RequiresPermissions("sf:cbtypeface:update")
    public R update(@RequestBody CbTypefaceEntity cbTypeface){
		cbTypefaceService.updateById(cbTypeface);

        return R.ok();
    }

    /**
     * 删除
     */
    @PostMapping("/delete")
    //@RequiresPermissions("sf:cbtypeface:delete")
    public R delete(@RequestBody Long[] ids){
		cbTypefaceService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

    /**
     * 通过editionId获取book和章节的级联菜单
     */
    @GetMapping("/getBookAndChapterByEditionId/{editionId}")
    //@RequiresPermissions("sf:cbtypeface:delete")
    public R getBookAndChapterByEditionId(@PathVariable("editionId") Long editionId){
        List<BookToUnitVo> list = cbTypefaceService.getBookAndChapterByEditionId(editionId);
        return R.ok().put("chapterList", list);
    }

}
